package httplib;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by niraymond on 16/8/18.
 */
public abstract class BaseInput extends BaseModel {
    private String date;
    private String direct;
    private String method;

    public abstract Map<String, String> getData();

    public String getData(String path) {
        if(path.contains("date")){
            return safeGetDtoData(this.date,path);
        }else if(path.contains("direct")){
            return safeGetDtoData(this.direct,path);
        }

        return super.getData(path);
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void setDirect(String direct) {
        this.direct = direct;
    }

    public String getDate() {
        return "2016-08-22";
    }

    public String getDirect() {
        return "true";
    }

    public String getMethod() {
        return method;
    }

    public HashMap<String, Method> getProperties() throws NoSuchMethodException {
        HashMap<String, Method> map = new HashMap<>();
        //调用时很可能是子类对象，必须使用getMethod，而不是getDeclaredMethod来获取方法。
        map.put("date", this.getClass().getMethod("getDate", null));
        map.put("direct", this.getClass().getMethod("getDirect", null));
        map.put("method", this.getClass().getMethod("getMethod", null));
        return map;
    }
}
